﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

/// <summary>
///log 的摘要说明
/// </summary>
/// 
namespace WeiXin
{
    static public class Log
    {

        /// <summary>
        /// 日志
        /// </summary>
        /// <param name="p"></param>
        static public void WriteLog(string p)
        {
            //日志写在工程根目录  ~/logs/log.txt
            if (!Directory.Exists(System.Web.HttpContext.Current.Server.MapPath(@"logs")))
            {
                Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(@"logs\"));
            }
            string filename = System.Web.HttpContext.Current.Server.MapPath(@"logs/log.txt");
            StreamWriter sr = null;
            try
            {
                if (!File.Exists(filename))
                {
                    sr = File.CreateText(filename);
                }
                else
                {
                    sr = File.AppendText(filename);
                }
                string output = p ;
                sr.WriteLine(output);
            }
            catch
            {
            }
            finally
            {
                if (sr != null)
                    sr.Close();
            }
        }
    }
}